package com.entrogy.utils;

import com.entrogy.bean.PassRecordEntity;
import com.entrogy.timing.StuRecordServiceTask;

import java.util.concurrent.*;

public class StudentRecordUtil extends Thread {
    private ExecutorService executor;


    public StudentRecordUtil() {
        super();
//        executor = new ThreadPoolExecutor(5, 10, 200, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(5));
        executor = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
    }

    @Override
    public void run() {
        super.run();
        while (true) {
            PassRecordEntity passRecordEntity = QueueUtils.pollQueue();
            if (passRecordEntity != null) {
                StuRecordServiceTask task = new StuRecordServiceTask(passRecordEntity);
                executor.execute(task);
            }
            if (passRecordEntity == null) {
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }

    @Override
    public synchronized void start() {
        super.start();
    }
}
